<template>
    <div class="box">
        <van-form @submit="onSubmit">
            <van-cell-group inset>

                <van-field v-model="RYD_Name" name="RYD_Name" label="名称" placeholder="请输入名称"
                    :rules="[{ required: true, message: '请输入正确内容' }]" size="large" maxlength='10' />

                <van-field v-model="RYD_Phone" name="RYD_Phone" label="联系方式" placeholder="请输入分机号或者手机号"
                    :rules="[{ required: true, message: '请输入正确内容' }]" size="large" maxlength='10' />

                <van-field v-model="RYD_RegId" name="RYD_RegId" label="注册号" placeholder="请输入注册号"
                    :rules="[{ required: true, message: '请输入正确内容' }]" size="large" maxlength='10' />

            </van-cell-group>

            <van-cell-group inset>
                <van-cell title="事件类别" label="请选择你负责的事件类别">

                    <van-checkbox-group v-model="RYD_DemandTypeNo" name="RYD_DemandTypeNo">
                        <van-cell v-for="item in typeList" v-bind:key="item.ryD_DemandTypeNo">
                            <van-checkbox shape="square" :name="item.ryD_DemandTypeNo">{{ item.ryD_DemandTypeName }}
                            </van-checkbox>
                        </van-cell>
                    </van-checkbox-group>
                </van-cell>

            </van-cell-group>
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    提交
                </van-button>
            </div>
        </van-form>

    </div>
</template>

<script setup>

import axios from '@/utils/axios';
import { inject, ref } from 'vue';
import { Dialog, Toast } from 'vant';
import router from '@/router';

let nav = inject('nav');
nav.showLeft = true;
nav.textLeft = '返回';
nav.title = 'IT 注册';
nav.showRight = false;

let RYD_Name = ref('');
let RYD_Phone = ref('');
let RYD_RegId = ref('');

let RYD_DemandTypeNo = ref();

let typeList = ref();

let RYD_UserId = inject('RYD_UserId');

let RYD_Company = '';

Dialog.confirm({
    title: "提示",
    message: "该功能只允许IT部门使用，是否继续？",
}).then(() => {

}).catch(() => {
    router.back();
})
let onSubmit = (values) => {

    if (RYD_DemandTypeNo.value == null) {
        Toast.fail({ overlay: true, message: '请选择你负责的事件类别' })
        return;
    }
    if (RYD_DemandTypeNo.value.length == 0) {
        Toast.fail({ overlay: true, message: '请选择你负责的事件类别' })
        return;
    }
    Toast.loading({
        message: '注册中',
        duration: 0,
        overlay: true
    });
    axios({
        method: 'Put',
        url: '/api/UserInfo',
        data: {
            ...values,
            RYD_UserId,
            RYD_DemandTypeNo: RYD_DemandTypeNo.value,
            RYD_Company: RYD_Company
        }
    }).then(res => {
        if (res == true) {
            Toast.success({ overlay: true, message: '注册成功' });
            router.replace('AndroidHomePage');
        } else {
            Toast.fail({ overlay: true, message: '注册失败' })
        }
    }).catch(() => {
        Toast.fail({ overlay: true, message: '错误' })
    })
}
initDate();
function initDate() {
    axios({
        method: 'get',
        url: '/api/GetCompany?RYD_UserId=' + RYD_UserId
    }).then(res => {
        RYD_Company = res;
        axios({
            method: 'get',
            url: '/api/DemandType?RYD_Company=' + res
        }).then(typeListres => {
            typeList.value = typeListres;
        })
    })
}

</script>


<style scoped>
/* .box {
    padding-top: ;
} */
</style>